<?php
/**
 * This is an idea I got from Shaun Inman. Basically it forces whatever text is passed
 * to it to NOT have a widow. A widow is when you have one word that is on the last line
 * of a block of text (usually used for headers). The following sentance has a widow.
 * 
 * This sentence is just long enough that it requires one word to bump down to the next
 * line.
 * 
 * Widows are considered bad practice. The way it works is that it places a non-breakable
 * space between the last two words.
 */
class ImpSoft_View_Helper_Widont {

    public $view;
    
    public function widont($str = '', $escape = true) {
    
        if ($escape) $str = $this->view->escape($str);
        return preg_replace( '|([^\s])\s+([^\s]+)\s*$|', '$1&nbsp;$2', $str);
    
    }
    
    public function setView($view) {
    
        $this->view = $view;
    
    }

}